package xyz.scootaloo.oj.leetcode

import org.junit.Test
import xyz.scootaloo.common.TestDsl

/**
 * @author flutterdash@qq.com
 * @since 2021/7/10 9:53
 */
class P73 : TestDsl {

    private fun setZeroes(matrix: Array<IntArray>) {
        val rowSet = mutableSetOf<Int>()
        val colSet = mutableSetOf<Int>()
        for (r in matrix.indices) {
            for (c in matrix[r].indices) {
                if (matrix[r][c] == 0) {
                    rowSet.add(r)
                    colSet.add(c)
                }
            }
        }

        for (r in rowSet) {
            for (c in matrix[r].indices) {
                matrix[r][c] = 0
            }
        }

        for (c in colSet) {
            for (r in matrix.indices) {
                matrix[r][c] = 0
            }
        }
    }

    @Test
    fun test0() {
        arrayOf(
            intArrayOf(1, 1, 1),
            intArrayOf(1, 0, 1),
            intArrayOf(1, 1, 1)
        ).apply { setZeroes(this) }
            .log()
    }

}
